/**********************************************************************************
***
***    Screencasting Teaching System C++ Library
***    Copyright (C) 2011  Jiri Novak <jiri.novak@petriny.net>
***                        Wadi Jalil Maluf <wadijm@gmail.com>
***
***    This file is part of the Screencasting Teaching System C++ Library.
***
***    This library is free software; you can redistribute it and/or modify
***    it under the terms of the GNU General Public License as published by
***   the Free Software Foundation; either version 3 of the License, or
***    (at your option) any later version.
***
***    This library is distributed in the hope that it will be useful,
***    but WITHOUT ANY WARRANTY; without even the implied warranty of
***    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
***   GNU General Public License for more details.
***
***    You should have received a copy of the GNU General Public License
***    along with this library; if not, write to the Free Software
***    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
***
*********************************************************************************/
#ifndef PROTOCOL_H_
#define PROTOCOL_H_
#include "../xmlutil.h"
#include "operation.h"
#include "../model/lesson.h"
#include "../model/chatmessage.h"
#include <string>
#include <log4cxx/logger.h>
/**
 * Clase encargada de serializar y deserializar mensajes entre el servidor y el cliente.
 */
class Protocol
{
public:
  const static char START_SCREENCAST=1;
  const static char LOGIN_REQUEST=2;
  const static char FIND_SHOWS=3;
  const static char LOGIN_FAILED=4;
  const static char LOGIN_SUCCESS=5;
  const static char SCREENCAST_DATA=6;
  const static char CHAT_MESSAGE=7;
  const static char START_SCREENCAST_RECORDING=8;
  const static char STOP_SCREENCAST=9;
  const static char START_SCREENCAST_PLAYBACK=10;
  const static char SCREENCAST_AUDIO_DATA=11;
  const static char SCREENCAST_NOT_AVAILABLE=12;
  const static char STOP_SCREENCAST_USER_REQUEST=13;
  const static char LOGOUT_REQUEST=14;
  Protocol();
  virtual
  ~Protocol();
  std::string getUsername(Operation& op);
  std::string getPassword(Operation& op);
  std::vector<char> buildLoginMessage(User* user);
  std::vector<char> buildChatMessage(ChatMessage* user);
  User* parseLoginMessage(Operation& op);
  std::vector<char> buildLoginRequest(std::string username,std::string password);
  std::vector<char> buildFindAllShowsRequest();
  std::vector<char> buildPlayScreenCast(Lesson* lesson);
  std::vector<char> buildStartScreenCast(Lesson* lesson);
  std::vector<char> buildStartAndSaveScreenCast(Lesson* lesson);
  std::vector<char> buildStopScreenCast(Lesson* lesson);
  std::vector<char> buildStopListeningScreenCast(Lesson* lesson);
  std::vector<char> buildScreencastData(Lesson* lesson,unsigned char* data,int size,int pts);
  std::vector<char>  buildScreencastAudioData(Lesson* lesson,unsigned char* data,int size,int pts);
  std::vector<char> buildLogoutRequest();
  std::vector<char> serializeShows( std::list<Course*> & courses, std::list<Lesson*> & lessonsToSerialize);
  void parseShows(Operation& op,std::list<Course*> & courses,std::list<Lesson*> & lessonsToSerialize);
  std::vector<char> buildScreencastFailed(Lesson* lesson);
  Lesson* parseLesson(Operation& op);
  ChatMessage* parseChatMessage(Operation& op);
  int parsePts(Operation& op);
private:
  log4cxx::LoggerPtr logger_;
  XmlUtil xmlUtil;
  std::vector<char> buildMessage(char type,std::string datos);
   void buildAvPacket(char type,std::vector<char>& data,int tamanio,int pts);
};

#endif /* PROTOCOL_H_ */
